#!/bin/bash
#c环境执行同步脚本

#脚本文件路径
path=/root/cShell

function check(){
        pt-table-sync --no-check-triggers --no-check-child-tables --no-foreign-key-checks  --charset=utf8 --verbose  --print h=172.16.3.177,u=read_only,p=winit2015,D=pis,t=pis_base_logistics_zone h=172.16.2.31,u=root,p=winit2015,D=pis,t=pis_base_logistics_zone
}


function start(){
        nohup pt-table-sync --no-check-triggers --no-check-child-tables --no-foreign-key-checks  --charset=utf8 --verbose  --print h=172.16.3.177,u=read_only,p=winit2015,D=pis,t=pis_base_logistics_zone h=172.16.2.31,u=root,p=winit2015,D=pis,t=pis_base_logistics_zone --execute > c.log &
}

function status(){
        pid=`ps -ef |grep -w "pt-table-sync" |grep -v grep |awk '{print $7}'|awk -F '/' '{print $1}'`
        if [ "${pid}" ] ;then
        echo "RUNNING"
        else
        echo "STOP"
        fi
}

function getlog(){
        cd ${path}
        cat c.log
}

case "$1" in
        check )
                check;;
        start )
                start;;
    status )
                status;;
        getlog )
                getlog;;
esac
exit 0